home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 14
/
Hot Mix 14.iso
/
HTML
/
vendors
/
finesse
/
examples
/
sh
/
fkill
< prev
next >
Wrap
Text File
|
1996-06-27
|
3KB
|
151 lines
#! /bin/sh
# FINESSEAPPLICATIONKEY sSEpSIGAcBCQe
#
# Demo script for killing processes with sh script
. ${FINESSEPATH-/usr/local/finesse}/fsshinit
# First check for tty
tty -s || { echo "Need a tty. Exiting." ; exit 1 ; }
# get list of processes and PID column number
#
list_proc()
{
list=`( ps $opt |
awk 'NR==1 { i=1; while ($i !~ /^PID$/) i++;
print "col="i;
print " proclist='\''"; }
NR>1 && $0 !~ /awk/ && /'"$patt"'.*/
END { print "'\''"; }'
) 2>errfile`
if [ -s errfile ] ; then
cat < errfile; /bin/rm -f errfile
exit 1
else
eval "$list"
/bin/rm -f errfile
fi
}
# update list of processes in kill window
#
update_list()
{
deletelist='*[delete]'
list_proc
addlist="`echo "$proclist" |
awk 'NR>1{ print $0"[add]" }'`"
updatearg="-v"
updatelist="procsinout=$deletelist$cr$addlist"
windowarg=
windowlist=
}
# check input
#
case "$1" in
?|help)
echo "Usage: fkill \
['<psoptions>'] [<pattern>]" >&2
exit 2 ;;
-*) opt=$1; comm="ps $opt" ; shift ;;
*) comm=ps;;
esac
patt="$1"
# get initial list of processes
# and declare window
#
# Start two demo processes to kill
sleep 60 &
sleep 60 &
list_proc
cr="
"
windef="
FsWindow -name killwin
-title `basename $0`;
FsSeparator -line no;
FsForm -name form1
-orientation horizontal
-packing tight
-spacing 30;
FsText -label Options: -parent form1
-var opt='$opt' -spacing 10
-bdefault update;
FsText -label Pattern: -name patt
-parent form1 -var patt='$patt'
-spacing 10 -bdefault update;
FsRadio -label Signals:
-items 'INT KILL TERM'
-var signal==TERM;
FsSeparator;
FsSeparator;
FsSeparator -line no;
FsList -label 'Select processes to kill:'
-items '$proclist'
-nvisible 10
-mode multiple
-inputsep '$cr'
-outputsep '$cr'
-var procsinout=''
-expert k;
FsSeparator;
FsPushButton -label Kill -name kill
-fsbutton k -winstat touch;
FsPushButton -label Update -name update
-fsbutton u -winstat touch;
FsPushButton -label Exit
-fsbutton e -nrows 1;"
# Open server and display window
#
Fsopen -o 3 "$@"
# Kill selected processes and/or update list
#
updatearg=
updatelist=
windowarg="-w"
windowlist="$windef"
while :
do
Fsdisplay "$windowarg" "$windowlist"\
"$updatearg" "$updatelist"\
-m "List and kill processes"\
-n killwin\
-v opt=$opt\
-v patt=$patt
case $fsbutton in
k) case $signal in
INT) SIG=2 ;;
KILL) SIG=9 ;;
TERM) SIG=15
esac
if [ "$procsinout" != "" ] ; then
kill -$SIG `echo "$procsinout" |
awk '{ print $'$col'}'`
update_list
else
updatelist=
updatearg=
Fsecho "No processes selected..."
fi ;;
u) update_list ;;
e|a) Fsclose; exit ;;
esac
windowarg=
windowlist=
done